<?php
    @header('Content-type:text/html;charset=utf-8');
    @include_once('conn.php');
    @include_once("noparams.php");

    $id = $_POST["id"];   // _POST 
    $chinese = $_POST["chinese"];
    $math = $_POST["math"];
    $english = $_POST["english"];   // 0 也是默认false 

    // 类型转换 
    // 0 == false
    // 1 == true 
    if(!($id&&$chinese>=0&&$math>=0&&$english>=0)){
        NoParamsErr();
    }

    $sql = "update grade set  chinese='$chinese',math='$math',english='$english' where id = $id";

    $result = mysqli_query($conn,$sql);

    if(!$result){
        $obj=array();
        $obj['status'] = false;
        $obj['detail'] = "Sql语句有问题";
        $obj['sql'] = $sql;
        exit(json_encode($obj));
    }

    $rows = mysqli_affected_rows($conn);

    $obj = array();
    if($rows>0){
        $obj['status'] = true;
        $obj['detail'] = '修改成功';
    }else{
        $obj['status'] = false;
        $obj['detail'] = '修改失败,数据未改变';
    }

    echo json_encode($obj);

?>

